﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace StrData
{

    interface IRunable
    {
        //规范子类必须实现strName属性
        string strName { get; set; }
        //规范子类必须实现Run()方法
        void Run();

    }


    public class Student1 : IRunable
    {
        string strname;

        public string strName { get => strname; set => strname = value; }

        public void Run()
        {
            Console.WriteLine("我是小学生，我在学校里面跑步！");
        }
    }

    class Student : IRunable
    {
        //这里是子类的字段
        string strname;
        //显示实现接口
        string IRunable.strName
        {
            get
            {
                return strname;
            }
            set
            {
                strname = value;
            }
        }

        void IRunable.Run()
        {
            Console.WriteLine("我是小学生，我在学校里面跑步！");
        }

        // Student s = new Student();


    }

    public class Worker : IRunable
    {
        string strname;
        public string strName { get => "工人"; set => strname = value; }

        public void Run()
        {

            Console.WriteLine("我是工人，我需要在厂区跑！");
        }
    }


    class Program
    {






        public static char[] ConvertToBinary(ulong flag, int count)
        {
            char[] result = new char[count];
            string str = Convert.ToString((long)flag, 2);
            if (str.Length < count)
            {
                str = str.PadLeft(count, '0');
            }

            char[] ch = str.ToArray();
            if (ch.Length > count)
            {
                for (int i = 0; i < count; i++)
                {
                    result[i] = ch[i];
                }
            }
            else
            {
                result = ch;
            }
            Array.Reverse(result);
            return result;
        }

        public static int CheckStatusFlag(char[] ch, int startIndex, int stopIndex, int code)
        {
            int errCode = 0;
            for (int i = startIndex; i < stopIndex + 1; i++)
            {
                if (ch[i] == '0')
                {
                    errCode = code + i;
#if NOERRDEBUG
                    if (errCode != 0)
                    {
                        m_Logger.Error(errCode);
                        errCode = 0;
                    }
#endif
                    return errCode;
                }
            }
            return errCode;
        }

        /// <summary>
        /// 正则表达式，截取两个字符串中间的字符串
        /// </summary>
        /// <param name="source">目标字符串</param>
        /// <param name="startStr">起始字符串</param>
        /// <param name="endStr">结束字符串</param>
        /// <returns>截取的结果</returns>
        private static string CutOutStr(string source, string startStr = "", string endStr = "")
        {
            Regex rg;
            if (endStr.Equals(""))  //提取特定字符串开头的内容
            {
                rg = new Regex("(?<=(" + startStr + "))[.\\s\\S]*");
            }
            else if (startStr.Equals(""))  //提取特定字符串结尾的内容
            {
                rg = new Regex(".*?(?=(" + endStr + "))");
            }
            else  //提取特定字符串开头与结尾之间的内容
            {
                rg = new Regex("(?<=(" + startStr + "))[.\\s\\S]*?(?=(" + endStr + "))");
            }
            return rg.Match(source).Value;
        }

        private static double CalNtcTemp(double ntc_R, double rt, double bx)
        {
            #region old

            //double Rp = 10000.0;
            //double T2 = (273.15 + 25.0);
            //double Bx = bx;
            //double Ka = 273.15;
            //double Rt = rt;
            //double temp = 0;
            //Rt = ntc_R;

            //temp = Rt / Rp;
            //temp = Math.Log(temp);//ln(Rt/Rp)
            //temp /= Bx;//ln(Rt/Rp)/B
            //temp += (1 / T2);
            //temp = 1 / (temp);
            //temp -= Ka;

            #endregion

            #region 2.0
            //double Rp = rt;
            //double T2 = (273.15 + 25.0);
            //double Bx = bx;
            //double Ka = 273.15;
            //double Rt = ntc_R;
            //double temp = 0;
            //temp = Rt / Rp;
            //temp = Math.Log(temp);//ln(Rt/Rp)
            //temp /= Bx;//ln(Rt/Rp)/B
            //temp += (1 / T2);
            //temp = 1 / (temp);
            //temp -= Ka;
            #endregion

            #region 3.0

            double Rp = 10000.0;
            double T2 = (273.15 + 25.0);
            double Bx = bx;
            double Ka = 273.15;
            double Rt = rt;
            double temp = 0;
            Rt = ntc_R;

            temp = Rt / Rp;
            temp = Rt / Rp;
            temp = Math.Log(temp);//ln(Rt/Rp)
            temp /= Bx;//ln(Rt/Rp)/B
            temp += (1 / T2);
            temp = 1 / (temp);
            temp -= Ka;

            #endregion

            //  m_Log.Info($"CalNtcTemp ntc_R:{ntc_R}, rt:{rt},bx:{bx},temp:{temp}");
            return temp;
        }

        private static double CalNtcTemp__(double ntc_R, double rt, double bx)
        {
            double Rp = rt;
            double T2 = (273.15 + 25.0);
            double Bx = bx;
            double Ka = 273.15;
            double Rt = ntc_R;
            double temp = 0;



            temp = Rt / Rp;
            temp = Math.Log(temp);//ln(Rt/Rp)
            temp /= Bx;//ln(Rt/Rp)/B
            temp += (1 / T2);
            temp = 1 / (temp);
            temp -= Ka;
            return temp;
        }

        private static string GetLotStr(string content)
        {
            var xxx = Regex.Replace(content, @"[^A-Z]+", "");
            var len = content.Length - content.IndexOf(xxx);
            len = len > 11 ? 11 : len;
            var str = content.Substring(content.IndexOf(xxx), len);
            return str;
        }

        private static void Test1()
        {
            Console.WriteLine("111111");
            var a = "1111";
            Thread.Sleep(6000);
            Console.WriteLine("22222");
        }

        private static async void Test()
        {
            Console.WriteLine("aaaa");
            HttpClient httpClient = new HttpClient();

            string html = await httpClient.GetStringAsync("https://baidu.com/");
            var Text = html.Substring(0, 200);
            Console.WriteLine("bbbb");
            await Task.Delay(3000);
            //Thread.Sleep(3000);
            Console.WriteLine("cccc");
            string html2 = await httpClient.GetStringAsync("https://www.cnblogs.com/");
            Text = html.Substring(0, 50);

        }

        static void Main(string[] args)
        {

            // Test1();
            Test();

            Console.WriteLine("33333");

            var aa = Math.Log(2);
            var bb = Math.Log10(2);


            IRunable s = new Student();
            s.strName = "小学生";
            s.Run();
            Console.WriteLine(s.strName);
            Console.WriteLine("--------------------");
            Worker w = new Worker();
            w.strName = "看我能不能渎职";
            w.Run();
            Console.WriteLine(w.strName);

            Console.ReadKey();




            //byte[] array = new byte[2] { 0x00, 0x1f };
            //Console.WriteLine(BitConverter.ToInt32(array, 1));



            ////  var l = GetLotStr("021XVGVD230167100");

            //// NTC:202.825042724609,rt5000,bx3436,Name:F_1通道,temp:139.853056152672
            //var cal = CalNtcTemp(202.825042724609, 5000, 3436);


            //string content = "021XVGVD23";
            //List<string> chs = new List<string>();
            //Regex reg = new Regex("[^A-Z]+");
            //foreach (Match v in reg.Matches(content))
            //    chs.Add(v.Value);

            //var xxx = Regex.Replace(content, @"[^A-Z]+", "");
            //var kk = content.Substring(content.IndexOf(xxx), 11);


            //string str = "021XVGVD2302";

            //string s = CutOutStr(str, "X", "");

            //double vcesat = 1.86424473;
            //double vce_ini = 1.86604919;

            //double deltaVce = (vcesat - vce_ini) / vce_ini;



            //List<string> errList = new List<string>() { "1011" };
            //int waitingTimes = 1000 * 60 * 2 / 100;
            //var bRetry = errList.IndexOf("0000") >= 0;




            //var aa = Math.Round(34.55555, 2, MidpointRounding.AwayFromZero);

            //var a1 = DateTime.Now;



            //double a = Convert.ToDouble(Console.ReadLine());
            //Console.WriteLine(a);
            //Console.ReadKey();

            //var str22 = "0.000030517578125";

            //var kk = double.Parse(str22);


            //char[] ch = ConvertToBinary((ushort)0, 1);

            //var CheckStatus = CheckStatusFlag(ch, 0, 0, 4001);

            //List<string> list = new List<string>();

            //string content = "PXV220159134PXV220290038PXV220290038";

            //var aaa = GetArrayContent(content);

            //int length = content.Length;

            //int count = length / 12;

            //for (var i = 1; i <= count; i++)
            //{
            //    int start = (i - 1) * 12;
            //    int end = start + 11;
            //    string str = content.Substring(start, 12);

            //    list.Add(str);
            //}






        }

        private static List<string> GetArrayContent(string content)
        {
            int step = 12;
            List<string> list = new List<string>();
            int length = content.Length;
            int count = length / step;
            for (var i = 1; i <= count; i++)
            {
                int start = (i - 1) * step;
                int end = start + 11;
                string str = content.Substring(start, step);
                list.Add(str);
            }
            return list;
        }


    }
}
